package com.carcenter.personnel.controller;

import cn.hutool.core.bean.BeanUtil;
import com.carcenter.common.result.Result;
import com.carcenter.common.pojo.personnel.UserDto;
import com.carcenter.personnel.entity.Users;
import com.carcenter.personnel.service.IUsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author car
 * @since 2025-07-16
 */
@RestController
@RequestMapping("/users")
public class UsersController {
    @Autowired
    private IUsersService usersService;

    @PostMapping("/getUserDtosByUserIds")
    public Result<List<UserDto>> getUserDtosByUserIds(@RequestBody List<Integer> userIds){
        List<Users> usersList = usersService.listByIds(userIds);
        List<UserDto> list = new ArrayList<>();
        for (Users user : usersList) {
            UserDto userDto = new UserDto();
            BeanUtil.copyProperties(user, userDto);
            list.add(userDto);
        }
        return Result.ok(list);
    }
}
